﻿using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Zavand.Web.Mvc.Manana.Framework;

namespace Zavand.Web.Mvc.Manana.FrameworkUnitTests
{
    ///<summary>
    ///    This is a test class for BaseControllerTest and is intended
    ///    to contain all BaseControllerTest Unit Tests
    ///</summary>
    [TestClass]
    public class BaseControllerTest
    {
        ///<summary>
        ///    A test for BaseController Constructor
        ///</summary>
        [TestMethod]
        public void BaseControllerConstructorTest()
        {
            var target = new BaseController();
            Assert.IsNotNull(target);
        }

        ///<summary>
        ///    A test for BaseController Constructor
        ///</summary>
        [TestMethod]
        public void BaseControllerConstructorOptionalParametersTest()
        {
            var requestContext = new RequestContext(new MockHttpContext(), new RouteData());
            requestContext.HttpContext.RemapHandler(new MvcHandler(requestContext));
            var controller = new UnitTestController();
            controller.ControllerContext = new ControllerContext {RequestContext = requestContext};

            // Put optional parameters
            for (int i = 0; i < 10; i++)
            {
                controller.ControllerContext.RequestContext.RouteData.Values.Add("anykey" + i, BaseUrlParameter.Optional);
            }
            controller.CallInitialize(controller.ControllerContext.RequestContext);

            Assert.IsTrue(controller.ControllerContext.RequestContext.RouteData.Values.Count == 0);
        }

        [TestMethod]
        public void SetupModelTest()
        {
            var controller = new UnitTestController();
            var r = new UnitTestRoute1();
            var m = new UnitTestModel1();
            controller.SetupModel(m,r,controller);

            Assert.AreSame(m.GetController(),controller);
            Assert.AreSame(m.GetRoute(),r);
        }

        [TestMethod]
        public void GetModelTest()
        {
            var controller = new UnitTestController();
            var r = new UnitTestRoute1();
            var m = controller.GetModel<UnitTestModel1,UnitTestRoute1,UnitTestController>(r,controller);

            Assert.AreSame(m.GetController(),controller);
            Assert.AreSame(m.GetRoute(),r);
        }
    }
}